<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\ordersSharedMysqlUsers;


Class OrdersSharedMysqlUsersModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }
    
    public function findAll()
    {
        $users = $this->em->getRepository('BillingBundle:ordersSharedMysqlUsers')->findAll();
        return $users;
    }
    
    public function FindByPK($user_id)
    {
        $user = $this->em->find('BillingBundle:ordersSharedMysqlUsers', $user_id);
        return $user;
    }

    public function findAllNotActive()
    {
        $emails = $this->em->getRepository('BillingBundle:ordersSharedMysqlUsers')->findBy(array('is_active' => "0"));
        return $emails;
    }
    
    public function findByBaseId($base_id)
    {
        $users = $this->em->getRepository('BillingBundle:ordersSharedMysqlUsers')->findBy(array('base_id' => $base_id));
        return $users;
    }

    public function findByBaseIdAndLogin($base_id, $login)
    {
        $user = $this->em->getRepository('BillingBundle:ordersSharedMysqlUsers')->findOneBy(array('base_id' => $base_id, 'login' => $login));
        return $user;
    }
    
    public function create($oEntity)
    {    
        $this->em->persist($oEntity);
        $this->em->flush();
    }
    
    public function removeByPK($user_id)
    {
        $user = $this->em->find('BillingBundle:ordersSharedMysqlUsers', $user_id);
        $this->em->remove($user);
        $this->em->flush();
    }
}
?>
